package com.sunyifeng.ch03;

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

/**
 * 3.4.3 java.util.function.Consumer<T>定义了accept(T t)的方法，无返回值
 */
public class ConsumerAccept {

    public static <T> void forEach(List<T> list, Consumer<T> c) {
        for (T i: list) {
            c.accept(i);
        }
    }

    public static void main(String[] args) {
        forEach(Arrays.asList(1, 2, 3, 4, 5),
                (Integer i) -> System.out.println(i)
        );
    }

}
